//
//  LoginViewController.m
//  久量
//
//  Created by 杨军 on 2017/9/28.
//  Copyright © 2017年 jay. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginModel.h"
#import "NSString+Extension.h"
#import <AVFoundation/AVFoundation.h>
//#import "registViewController.h"
//#import "forgetViewController.h"
//#import "conectListViewController.h"
//
//#import "LoginModel.h"
//
//
//#import <UMSocialCore/UMSocialCore.h>
//#import "HttpRequest.h"
//#import "XLinkExportObject.h"
//#import "DeviceEntity.h"



@interface LoginViewController ()
@property(nonatomic,strong)UITextField *phoneTF;
@property(nonatomic,strong)UITextField *passwordTF;
@end

@implementation LoginViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //[self.navigationController setNavigationBarHidden:YES animated:YES];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //[self.navigationController setNavigationBarHidden:NO animated:YES];
     
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //[self addNSNotificationWithStyles:@[kOnStart,kOnLogin]];

}

-(void)onLoadViewByWillAppear:(UIView *)view
{
    view.backgroundColor = [UIColor whiteColor];
   
    
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW/2-kFitW(100),kFitH(75), kFitW(200),kFitH(70))];
    imageV.image = IMAGE(@"login_login");
    [view addSubview:imageV];
    
    self.phoneTF = [[UITextField alloc]initWithFrame:CGRectMake(kFitW(30), imageV.bottom+kFitH(50),kScreenW-2*kFitW(30), kFitH(30))];
    self.phoneTF.placeholder = @"请输入手机号";
    self.phoneTF.text = @"18576705970";
    self.phoneTF.leftViewMode = UITextFieldViewModeAlways;
    self.phoneTF.clearButtonMode = UITextFieldViewModeAlways;
    self.phoneTF.keyboardType = UIKeyboardTypeNumberPad;
    [view addSubview:self.phoneTF];
    UIView *lineV = [[UIView alloc]initWithFrame:CGRectMake(kFitW(20), self.phoneTF.bottom, kScreenW-kFitW(40), 1)];
    lineV.backgroundColor = [UIColor blackColor];
    [view addSubview:lineV ];
    
    self.passwordTF = [[UITextField alloc]initWithFrame:CGRectMake(kFitW(30), self.phoneTF.bottom+kFitH(30),kScreenW-2*kFitW(30), kFitH(30))];
    self.passwordTF.placeholder = @"请输入密码";
    self.passwordTF.text = @"123456";
    self.passwordTF.leftViewMode = UITextFieldViewModeAlways;
    self.passwordTF.clearButtonMode = UITextFieldViewModeAlways;
    self.passwordTF.secureTextEntry = YES;
    [view addSubview:self.passwordTF];
    
    UIView *lineV1 = [[UIView alloc]initWithFrame:CGRectMake(kFitW(20),self.passwordTF.bottom, kScreenW-kFitW(40), 1)];
    lineV1.backgroundColor = [UIColor blackColor];
    [view addSubview:lineV1];
    
    
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    loginBtn.frame = CGRectMake(kFitW(20), lineV1.y+kFitH(30),kScreenW-kFitW(40), kFitH(40));
    [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    loginBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15.0];
    loginBtn.layer.cornerRadius = kFitW(20);
    loginBtn.backgroundColor = [UIColor redColor];
    [loginBtn addTarget:self action:@selector(loginBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:loginBtn];
    
    UIButton *forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    forgetBtn.frame = CGRectMake(kScreenW/2-kFitW(85), loginBtn.bottom+kFitH(15),kFitW(80),kFitH(20));
    [forgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
    [forgetBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    forgetBtn.titleLabel.font = kSysFont(kFitW(14));
    [forgetBtn addTarget:self action:@selector(forgetBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:forgetBtn];
    
    UIView *smallV = [[UIView alloc]initWithFrame:CGRectMake(kScreenW/2+kFitW(5), loginBtn.bottom+kFitW(15),kFitW(2), kFitH(20))];
    smallV.backgroundColor = [UIColor blackColor];
    [view addSubview:smallV];
    
    
    UIButton *registBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    registBtn.frame = CGRectMake(kScreenW/2+kFitW(5),loginBtn.bottom+kFitH(15), kFitW(80), kFitH(20));
    [registBtn setTitle:@"注册" forState:UIControlStateNormal];
    [registBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    registBtn.titleLabel.font = kSysFont(kFitW(14));
    [registBtn addTarget:self action:@selector(registBtn) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:registBtn];
    
//    UIView *aView=[LoginViewController lineLabelviewWithFrame:CGRectMake(kFitW(40), MaxY(registBtn)+kFitH(20), kScreenW-kFitW(80), kFitH(25)) labelString:@"授权登录" font:FONT_13 textColor:COLOR_LIGHTGRAY backgroundColor:COLOR_CLEAR];
//    [view  addSubview:aView];
    
//    NSArray *imageArray = [NSArray arrayWithObjects:@"weixin",@"qq",@"xinlang", nil];
//    NSArray *titleArray=[[NSArray alloc]initWithObjects:@"微信",@"QQ",@"微博", nil];
//
//    for (NSInteger i=0; i<3; i++)
//    {
//        UIButton *wxqqwbBtn=[[UIButton alloc]initWithFrame:CGRectMake(kFitW(45)+kFitW(90)*(i%3),MaxY(aView)+kFitH(20), kFitW(90), kFitH(90))];
//        wxqqwbBtn.tag=i;
//        wxqqwbBtn.clipsToBounds=YES;
//        wxqqwbBtn.layer.cornerRadius=WIDTH(wxqqwbBtn)/2.0;
//        //                        wxqqwbBtn.backgroundColor=COLOR_RED;
//        [wxqqwbBtn setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
//
//        [wxqqwbBtn addTarget:self action:@selector(wxqqwbBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//
//        [view addSubview:wxqqwbBtn];
//
//        UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(MaxX(wxqqwbBtn)-WIDTH(wxqqwbBtn)-kFitW(10), MaxY(wxqqwbBtn), WIDTH(wxqqwbBtn)+kFitW(10*2), kFitH(25))];
//        label.text=titleArray[i];
//        label.textColor=COLOR_LIGHTGRAY;
//        label.textAlignment=NSTextAlignmentCenter;
//        label.font=FONT_13;
//        [view addSubview:label];
//    }
    
  
}

-(void)onLoadAnimatedByDidAppear:(id)model
{
    UserInfoManager *Info = [UserInfoManager shareUser];
    
//    if(kStringIsEmpty(Info.account)==NO) {
//        self.phoneTF.text = Info.account;
//    }
//
//    if (Info.pwd.length) {
//        self.passwordTF.text = Info.pwd;
//    }
}


-(void)forgetBtnClick
{
//    forgetViewController *vc = [[forgetViewController alloc]init];
//    [self.navigationController pushViewController:vc animated:YES];
    [LoginModel param1:nil successBlock:^(id data) {
        
    } falieBlock:^(NSString *error) {
        
    } errorBlock:^(id error) {
        
    }];
    
    
}
-(void)registBtn
{
//    registViewController *vc = [[registViewController alloc]init];
//    [self.navigationController pushViewController:vc animated:YES];
}
-(void)wxqqwbBtnClick:(UIButton *)button
{
    
}

-(void)onRootViewController
{
//    [UIView transitionWithView:[UIApplication sharedApplication].keyWindow duration:0.5f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
//        BOOL oldState = [UIView areAnimationsEnabled];
//        [UIView setAnimationsEnabled:NO];
//        UIWindow *window = [UIApplication sharedApplication].delegate.window;
//        conectListViewController * vc = [[conectListViewController alloc]init];
//        window.rootViewController = [[UINavigationController alloc]initWithRootViewController:vc];
//        [UIView setAnimationsEnabled:oldState];
//    } completion:^(BOOL finished) {
//
//    }];
}
#pragma mark---登录
-(void)loginBtnClick
{

    WSELF(weakSelf);
    
    //apiLogin @{@"userId":self.phoneTF.text,@"password":[self.passwordTF.text MD5string]}
    //apiCommonLogout
    
     //apiSetPsw @{@"userId":self.phoneTF.text,@"oldPassword":self.passwordTF.text@"newPassword":@"456789"}
    //@{@"userId":@"liangbq",@"password":@"123456"}
    
//    AVSpeechUttrance          代表你想说什么
    
//    AVSpeechSynthesizer      用来发出声音
    
//    NSArray *ary = [AVSpeechSynthesisVoice speechVoices]; //获取系统提供的语言种类
    
//    AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
//    
//    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"一是能识人。知人善恶，账目不负,二是能接纳。礼文相待，交往者众,三是能安业。厌故喜新，商贾大病,四是能整顿。货物整齐，夺人心目,五是能敏捷。犹豫不决，终归无成,六是能讨帐。勤谨不怠，取行自多,七是能用人。因才四用，任事有赖,八是能辨论。生财有道，阐发愚蒙,九是能办货。置货不苛，蚀本便经,十是能知机。售宁随时，可称名哲,十一是能倡率。躬行必律，亲感自生,十二是能运数。多寡宽紧，酌中而行"];    //设置你想说的话
//    
//    utterance.rate = AVSpeechUtteranceDefaultSpeechRate /2; //设置语速
//    
////    utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-HK"]; //设置哪国语言
//    utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CH"]; //设置哪国语言
//    
//    [synthesizer speakUtterance:utterance];
    
    
    //添加进入发出声音类
    
    [LoginModel param:nil successBlock:^(id data) {

    } falieBlock:^(NSString *error) {

    } errorBlock:^(id error) {

    }];
}
//#pragma mark Xlink Delegate
-(void)getDataPointWithAccessToken:(NSString *)accessToken{

}
-(void)showWarningAlert:(NSString *)msg{
    [self showWarningAlert:msg didFinish:nil];
}
-(void)showWarningAlert:(NSString *)msg didFinish:(void (^)(void))finish{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (finish != nil) {
            finish();
        }
    }];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:true completion:nil];
}

 
@end
